package org.example.springboot.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.example.springboot.entity.Employee;
import org.example.springboot.mapper.EmployeeMapper;
import org.springframework.stereotype.Service;

import java.util.List;

//service包是处理数据的 把mapper中增删改查的数据通过service包处理
//然后service包再把处理后的数据交给接口controller 通过controller再暴露出去给浏览器
//创建service把他标志成springboot里的一个bean
@Service
public class EmployService {
    @Resource
    private EmployeeMapper employeeMapper;//通过mapper把数据查出来



    public List<Employee> selectAll() {
        return employeeMapper.selectAll();
        //相当于
//        List<Employee> list = employeeMapper.selectAll();
//        return list;
    }

    public  Employee selectById(Integer id) {
        return employeeMapper.selectById(id);
    }

    public List<Employee> selectList(Employee employee) {
        return employeeMapper.selectList(employee);
    }

    //分页查询返回一个分页数据 泛型是返回的数据类型
    public PageInfo<Employee> selectPage(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);//PageHelper插件帮你做分页查询的页码和一页的数据 一些分页参数
        List<Employee> list = employeeMapper.selectAll();//然后通过employeeMapper进行查询
        return PageInfo.of(list);
    }

    public void add(Employee employee) {
        employeeMapper.insert(employee);

    }

    public void update(Employee employee) {
        employeeMapper.updateById(employee);
    }

    public void deleteById(Integer id) {
        employeeMapper.deleteById(id);
    }
}
